import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-04-16
 * Time: 11:10
 */
public class TestDemo3 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while(true){
            System.out.println("请输入用户名");
            String userName=scanner.nextLine();
            if(checkUserName(userName)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("请输入真实姓名");
            String realName=scanner.nextLine();
            if(checkRealName(realName)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("请输入密码");
            String  password1=scanner.nextLine();
            System.out.println("请再输入密码");
            String password2=scanner.nextLine();
            if(checkPassword(password1,password2,userName)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("请输入邮箱");
            String email=scanner.nextLine();
            if(checkEmail(email)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("电话号码");
            String tel=scanner.nextLine();
            if(checkTell(tel)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("请输入邮政编码");
            String postalCode=scanner.nextLine();
            if(checkPostalCode(postalCode)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            System.out.println("请输入身份证号码");
            String id=scanner.nextLine();
            if(checkId(id)){
                System.out.println("输入成功");
            }else{
                System.out.println("输入格式有误，重新输入");
                continue;
            }
            break;
        }
    }
    public static boolean checkUserName(String str){
        return str.matches("^[a-z0-9_]{6,18}$");
    }
    public static boolean checkRealName(String str){
        return str.matches("^[\u4E00-\u9FA5]{2,4}$");
    }
    public static boolean checkPassword(String str1,String str2,String str3){
       if(str1.equals(str2)){
           return  str1.matches("^[a-zA-Z0-9@！#、]{8,}$");
       }
       return false;
    }
    public static boolean checkEmail(String str){
        return str.matches("^([a-zA-Z][a-zA-Z0-9_.]{4,19})@([0-9a-zA-Z_.]{1,10})\\.(com.cn|com.cn.net)$");
    }
    public static boolean checkTell(String str){
        return str.matches("^([0-9]{11}|[0-9]{7}|[0-9]{3,4}\\_[0-9]{7})$");
    }
    public static boolean checkPostalCode(String str){
        return str.matches("^[0-9]{6}$");
    }
    public static boolean checkId(String str){
        return str.matches("^([0-9]{15}|[0-9]{18}|[0-9]{17}X)$");
    }
}
